package org.q.threads;

import org.q.StartMain;


public class SubThreadWithExecption2 extends Thread {

	@Override
	public void run() {
		System.out.println("SubThreadWithExecption2,"+Thread.currentThread().getName());
		try {
			if(randomInt(1, 6)/4 == 0) {
//				System.out.println(1/0);
//				throw new Exception("exception test");
			}
			if(StartMain.SHUTDOWN) {
				System.out.println("监听到线程结束信号， 跳出SubThreadWithExecption2:" + Thread.currentThread().getName());
			} else {
				System.out.println("SubThreadWithExecption2开始休眠...");
				Thread.sleep(5000);
			}
		} catch (Exception e) {
			System.out.println(Thread.currentThread().getName() + "终止休眠。。。");
		}
	}
	
	public static int randomInt(int min, int max) {
		return min + (int)(Math.random() * (max - min));
	}
	
}
